package com.crm.jdy.service.client;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.crm.jdy.common.dto.SupplierInfoDto;
import com.crm.jdy.common.mapper.ReturnPlanInfoMapper;
import com.crm.jdy.common.pojo.ClientChargeInfo;
import com.crm.jdy.common.pojo.SupplierInfo;
import com.crm.jdy.common.mapper.SupplierInfoMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**   
 * @Description:(供应商管理服务实现)
 *
 * @version: V1.0
 * @author: kong
 * 
 */
@Service(version = "${service.version}")
@Component
public class SupplierInfoServiceImpl  extends ServiceImpl<SupplierInfoMapper,SupplierInfo> implements SupplierInfoService  {


    @Autowired
    SupplierInfoMapper supplierInfoMapper;

    @Override
    public PageInfo<SupplierInfo> seleteSupplierInfo(SupplierInfoDto callAplanInfoDto) {
          PageHelper.startPage( callAplanInfoDto.getCurrentPage(),callAplanInfoDto.getPageSize());
          List<SupplierInfo> bookList = supplierInfoMapper.seleteSupplierInfo(callAplanInfoDto);
          PageInfo<SupplierInfo> pageInfo = new PageInfo<SupplierInfo>(bookList);
        return pageInfo;
    }

    @Override
    public boolean updateSupplierInfo(SupplierInfo supplierInfo) {
        return supplierInfoMapper.updateById(supplierInfo) > 0;
    }

    @Override
    public boolean addSupplierInfo(SupplierInfo supplierInfo) {
        LambdaQueryWrapper<SupplierInfo> lambda = new QueryWrapper<SupplierInfo>().lambda()
            .eq(SupplierInfo::getSupName, supplierInfo.getSupName());
        SupplierInfo clientInfo = supplierInfoMapper.selectOne(lambda);
            if( clientInfo !=null && ObjectUtils.isEmpty(clientInfo)){
            return false;
        }else{
            return supplierInfoMapper.insert(supplierInfo) > 0;
        }
    }

    @Override
    public boolean removeSupplierInfo(String supId) {
        return supplierInfoMapper.deleteById(supId) > 0;
    }


}